import 'package:flutter/material.dart';
import 'package:xim/common/module/qr.dart';
import 'package:xim/common/style/colors.dart';
import 'package:xim/config/route_config.dart';
import 'package:xim/http/store.dart';
import 'package:xim/widget/common/state.dart';
import 'package:xim/widget/common/ui/cell.dart';

class AddFriendPage extends StatefulWidget {
  const AddFriendPage({Key? key}) : super(key: key);

  @override
  State<AddFriendPage> createState() => _AddFriendPageState();
}

class _AddFriendPageState extends AppBarState<AddFriendPage> with BrightnessModeState<AddFriendPage>{

  ModelColor bgColor = ModelColor(darkColor: const Color(0xff111111), lightColor: const Color(0xffededed));
  ModelColor textColor = ModelColor(lightColor: const Color((0xff161616)), darkColor: const Color(0xffcecece));
  ModelColor fgColor = ModelColor(lightColor: const Color(0xfffefefe), darkColor: const Color(0xff181818));
  ModelColor weakTextColor = ModelColor(lightColor: const Color(0xff737373), darkColor: const Color(0xff8c8c8c));
  ModelColor inputBorder = ModelColor(lightColor: const Color(0xff181818), darkColor: const Color(0xff272727));
  ModelColor dividerColor = ModelColor(lightColor: const Color(0xffededed), darkColor: const Color(0xff1e1e1e));

  @override
  String get appBarTitle => "添加朋友";

  var inputFocusNode = FocusNode();

  @override
  double get elevation => 0;

  @override
  List<ModelColor> get brightnessColors => [
    bgColor, textColor,fgColor,
    weakTextColor,inputBorder,dividerColor
  ];

  @override
  Color get appBarBgColor => bgColor.color;

  @override
  IconThemeData get iconTheme => IconThemeData(color: textColor.color);

  @override
  TextStyle get appBarTitleStyle => TextStyle(color: textColor.color, fontSize: 14);

  @override
  Widget build(BuildContext context) {
    initModelColor(context);
    return Scaffold(
      appBar: appBar,
      body: Container(
        color: bgColor.color,
        padding: const EdgeInsets.symmetric(horizontal: 6),
        child: Column(
          children: [
            TextField(
              readOnly: true,
              onTap: ()=>Routers.toAddFriendSearchPage(),
              focusNode: inputFocusNode,
              style: TextStyle(color: textColor.color, fontSize: 14),
              decoration: InputDecoration(
                prefixIcon: Icon(Icons.search, size: 18, color: textColor.color,),
                hintText: "账号/昵称",
                hintStyle: TextStyle(fontSize: 14, color: weakTextColor.color),
                enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: inputBorder.color,width: 1.0)),
                border: UnderlineInputBorder(borderSide: BorderSide(color: inputBorder.color,width: 1.0)),
                focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: inputBorder.color,width: 1.0)),
                // enabledBorder: InputBorder.none,
              ),
            ),
            const SizedBox(height: 24,),
            scanCell,
            divider,
            sessionCell,
            divider,
            qrCell,
          ],
        ),
      ),
    );
  }

  Widget get divider => Container(
    height: 0.8,
    color: dividerColor.color,
  );

  Widget get scanCell => Cell(
    onTab: ()=>Routers.toScanPage(),
    decoration: BoxDecoration(
      color: fgColor.color,
    ),
    padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 12),
    leftItem: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("扫一扫", style: TextStyle(color: textColor.color, fontSize: 14),),
        Text("扫描二维码名片", style: TextStyle(color: weakTextColor.color, fontSize: 12),),
      ],
    ),
    rightItem: Icon(Icons.chevron_right, color: textColor.color,),
  );

  Widget get sessionCell => Cell(
    decoration: BoxDecoration(
      color: fgColor.color,
    ),
    padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 12),
    leftItem: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("从群里添加", style: TextStyle(color: textColor.color, fontSize: 14),),
        Text("从群中添加好友", style: TextStyle(color: weakTextColor.color, fontSize: 12),),
      ],
    ),
    rightItem: Icon(Icons.chevron_right, color: textColor.color,),
  );

  Widget get qrCell => Cell(
    onTab: () async {
      var currAccount = await getUserAccount();
      Routers.toQrPage(PageRouteQrResult("/profile/public/$currAccount"));
    },
    decoration: BoxDecoration(
      color: fgColor.color,
    ),
    padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 12),
    leftItem: Column(
      mainAxisAlignment: MainAxisAlignment.center,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text("二维码名片", style: TextStyle(color: textColor.color, fontSize: 14),),
        Text("我的二维码名片", style: TextStyle(color: weakTextColor.color, fontSize: 12),),
      ],
    ),
    rightItem: Icon(Icons.chevron_right, color: textColor.color,),
  );

}
